use super::{err, err_value, json, ok, throw_err, Base, Client, ECode, Resp, VBase, VMap, Value};

pub struct BackUp;

impl Base for BackUp {}

impl BackUp {
    pub async fn do_cmd(&self, para: &Value, cmd: &str, client: &Client) -> Resp {
        let data = para.ckobj()?;
        let path = data.ck_str("p")?;

        match cmd {
            "save" => client.backup(path),
            "info" => client.backup_info(path),
            "rm" => {
                let num = data.ck_i64("num")?;
                client.del_bk(path, num)?;

                ok!()
            }
            "restore" => {
                let id = data.k_i64("id");
                client.restore(path, id)?;

                ok!()
            }
            _ => throw_err!(ECode::NoServe, "no backup serve"),
        }
    }
}
